package com.changgou;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import org.csource.common.MyException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author codeDorado
 * @version 1.0
 * @date 2020/7/17 11:33
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class ChanggouFileApplication {

    @Autowired
    OSSClient ossClient;

    @Value("${aliyun.oos.bucketName}")
    private String bucketName;

    @Test
    public  void upload() throws IOException {
        // 上传文件流。
        InputStream inputStream = new FileInputStream("C:\\Users\\86178\\Desktop\\1.jpg");
        ossClient.putObject(bucketName,"2.jpg",inputStream);
        // 关闭OSSClient。
        ossClient.shutdown();
        System.out.println("ok");
    }
}
